//
//  PublicDefine.h
//  GQHotel
//
//  Created by cienet on 14-5-13.
//  Copyright (c) 2014年 cienet. All rights reserved.
//

#pragma mark -
#pragma mark International

// Get localize string with key from InfoPlist.
#define CLLocalizedString(key) \
        NSLocalizedStringFromTable(key, @"Localizable", nil)


#define CLASSNAME(x) NSStringFromClass([(x) class])


#define BGCOLOR                         [UIColor whiteColor]

#define BORDERCOLOR                     [UIColor colorWithRed:215.0f/255.0f green:215.0f/255.0f blue:215.0f/255.0f alpha:1.0]
//#0bdcfe
#define BORDERHIGHLIGHTEDCOLOR          [UIColor colorWithRed:11.0f/255.0f green:220.0f/255.0f blue:254.0f/255.0f alpha:1.0]

#define TEXTCOLOR                       [UIColor blackColor]
#define TEXTHIGHLIGHTEDCOLOR            BORDERHIGHLIGHTEDCOLOR

#define BACKIMAGE @"back_ico"

#define iOS8Font(fontSize) [UIFont fontWithName:kfontName size:fontSize]
#define kfontName @"Helvetica"


#pragma mark -
#pragma mark Color

#define BUTTUN_COLOR    CLRgbaColor(17, 125, 218, 1.0f)
#define NAV_COLOR    CLRgbaColor(38, 54, 70, 1.0f)

#define CLRgbColor(r,g,b) [UIColor colorWithRed:(r)/255.0f green:(g)/255.0f blue:(b)/255.0f \
        alpha:1]
#define CLRgbaColor(r,g,b,a) [UIColor colorWithRed:(r)/255.0f green:(g)/255.0f blue:(b)/255.0f \
        alpha:(a)]

#define CLHsvColor(h,s,v) [UIColor colorWithHue:(h) saturation:(s) value:(v) alpha:1]
#define CLHsvaColor(h,s,v,a) [UIColor colorWithHue:(h) saturation:(s) value:(v) alpha:(a)]

#pragma mark -
#pragma mark Device Check

#define CLSystemVerison ([[UIDevice currentDevice] systemVersion])
#define CLIsiPad (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)

#define CL_SYSTEM_VERSION_EQUAL_TO(v) \
      ([CLSystemVerison compare:v options:NSNumericSearch] == NSOrderedSame)

#define CL_SYSTEM_VERSION_GREATER_THAN(v)\
      ([CLSystemVerison compare:v options:NSNumericSearch] == NSOrderedDescending)

#define CL_SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(v)\
      ([CLSystemVerison compare:v options:NSNumericSearch] != NSOrderedAscending)

#define CL_SYSTEM_VERSION_LESS_THAN(v)\
      ([CLSystemVerison compare:v options:NSNumericSearch] == NSOrderedAscending)

#define CL_SYSTEM_VERSION_LESS_THAN_OR_EQUAL_TO(v) \
      ([CLSystemVerison compare:v options:NSNumericSearch] != NSOrderedDescending)

#pragma mark -
#pragma mark Screen

#define CLScreenWidth   ([UIScreen mainScreen].bounds.size.width)
#define CLScreenHeight  ([UIScreen mainScreen].bounds.size.height)

#ifndef iPhone4s
#define iPhone4s CLScreenHeight == 480 ? YES : NO
#endif

#ifndef iPhone5
#define iPhone5  CLScreenHeight == 568 ? YES : NO
#endif

#ifndef iPhone6
#define iPhone6 CLScreenHeight == 667 ? YES : NO
#endif

#ifndef iPhone6P
#define iPhone6P   CLScreenHeight == 736 ? YES : NO
#endif

#pragma mark -
#pragma mark View

#define CLViewLeft(view) (view.frame.origin.x)
#define CLViewRight(view) (view.frame.origin.x + view.frame.size.width)
#define CLViewTop(view) (view.frame.origin.y)
#define CLViewBottom(view) (view.frame.origin.y + view.frame.size.height)
#define CLViewWidth(view) (view.frame.size.width)
#define CLViewHeight(view) (view.frame.size.height)

#pragma mark -
#pragma mark - GCD

#define CLGcdBack(block) dispatch_async(\
        dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), block)
#define CLGcdMain(block) dispatch_async(dispatch_get_main_queue(),block)

#pragma mark -
#pragma mark - Date

#define CLCurrentTimeInMilliSince1970 ([[NSDate date] timeIntervalSince1970] * 1000)

#define CLLocalDate(gtmTimeInterval) \
        ([NSDate dateWithTimeInterval:[[NSTimeZone localTimeZone] secondsFromGMT] \
                            sinceDate:[NSDate dateWithTimeIntervalSince1970:gtmTimeInterval]])

#define CLCurrentTimeZeroZoneForSeconds \
    ([[NSDate date] timeIntervalSince1970] - [[NSTimeZone localTimeZone] secondsFromGMT])



#pragma mark -
#pragma mark - Simple Alert

#define CLAlert(msg) ([CLProgressHUD showMessage:msg])

#define CLAlertWithOkButton(title, msg)        \
    ([[[CLAlertView alloc] initWithTitle:title \
                                  message:msg   \
                                 delegate:nil   \
                        cancelButtonTitle:CLLocalizedString(@"Global_Dialog_OK") \
                        otherButtonTitles:nil] show])

#define CLAlertWithCancelAndOkButton(title, msg) \
    ([[CLAlertView alloc] initWithTitle:title \
                                message:msg \
                               delegate:nil \
                      cancelButtonTitle:CLLocalizedString(@"Global_Cancel") \
                      otherButtonTitles:CLLocalizedString(@"Global_Dialog_OK"), nil])

#define CLAlertRetry(title, msg) \
    ([[CLAlertView alloc] initWithTitle:title \
                                 message:msg \
                                delegate:nil \
                       cancelButtonTitle:CLLocalizedString(@"Global_Retry") \
                       otherButtonTitles:nil])

#define CLAlertRetryAndOK(title, msg) \
    ([[CLAlertView alloc] initWithTitle:title \
                                 message:msg \
                                delegate:nil \
                       cancelButtonTitle:CLLocalizedString(@"Global_Retry") \
                       otherButtonTitles:CLLocalizedString(@"Global_Dialog_OK"), nil])


#define CLKeepAlert(msg) \
        ([[[CXAlertView alloc] initWithTitle:nil \
                                     message:msg \
                           cancelButtonTitle:CLLocalizedString(@"Global_Dialog_OK")] show])

#define CLKeepAlertWithOkButton(title, msg) \
        ([[[CXAlertView alloc] initWithTitle:title \
                                     message:msg \
                           cancelButtonTitle:CLLocalizedString(@"Global_Dialog_OK")] show])

#pragma mark -
#pragma mark - Dismiss warning

#define DISMISS_SELECTOR_WARNING(code)                        \
    _Pragma("clang diagnostic push")                                        \
    _Pragma("clang diagnostic ignored \"-Warc-performSelector-leaks\"")     \
    code;                                                                   \
    _Pragma("clang diagnostic pop")                                         \


#pragma mark -
#pragma mark - Utils

#define CLNSDictionaryCopy(dict) \
    ([[NSMutableDictionary alloc] initWithDictionary:dict copyItems:YES])

#define CLNSArrayCopy(array) \
    ([[NSMutableArray alloc] initWithArray:array copyItems:YES])

#define CL_ARRAY_INDEX_SET(array) \
    ([NSIndexSet indexSetWithIndexesInRange:NSMakeRange(0, array.count)])
#define CL_PRINT_VIEW_RECT(view)\
    (NSLog(@"left:%f-top:%f-width:%f-height:%f", \
        CLViewLeft(view), CLViewTop(view), CLViewWidth(view), CLViewHeight(view)))
#define CL_PRINT_RECT(rect)\
    (NSLog(@"left:%f-top:%f-width:%f-height:%f", \
       rect.origin.x, rect.origin.y, rect.size.width, rect.size.height))


#pragma mark -
#pragma mark - FilePath

#define CL_DOCUMENT_DIR \
    ([NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, \
                                          NSUserDomainMask, \
                                          YES) \
      objectAtIndex:0])

#define CL_EXIST_FILE(filePath) ([[NSFileManager defaultManager] fileExistsAtPath:filePath])

#define CL_CREATE_DIR(path, createDirectories, attributesDic, nsError) \
    ([[NSFileManager defaultManager] createDirectoryAtPath:path \
                               withIntermediateDirectories:createDirectories \
                                                attributes:attributesDic \
                                                     error:&nsError])


#pragma mark -
#pragma mark - Get image

#define CLImage(name ,ext) \
    ([UIImage imageWithContentsOfFile: \
      [NSString stringWithFormat:@"%@/%@.%@", [[NSBundle mainBundle] resourcePath], name, ext]])

#define CLPNGImage(name) (CLImage(name, @"png"))
#define CLJPGImage(name) (CLImage(name, @"jpg"))

#define CLImageSize(path) ([UIImage imageWithContentsOfFile:path].size)
#define CLImageWidth(image) (image.size.width)
#define CLImageHeight(image) (image.size.height)

#pragma mark -
#pragma mark - String

#define CLStringTrimWhiteSpace(string) \
    [string stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]]

#define CLStringByAppendingString(first, second) \
    [first stringByAppendingString:(second.length > 0)?second:@""]

#define CLStringEqual(nsString1, nsString2) \
    (NSOrderedSame == [nsString1 compare:nsString2])

#if __IPHONE_OS_VERSION_MIN_REQUIRED >= 70000
    #define CLTEXTSIZE(text, font) [text length] > 0 ? [text \
        sizeWithAttributes:@{NSFontAttributeName:font}] : CGSizeZero;
#else
    #define CLTEXTSIZE(text, font) [text length] > 0 ? [text sizeWithFont:font] : CGSizeZero;
#endif

#if __IPHONE_OS_VERSION_MIN_REQUIRED >= 70000
    #define CLMULTILINE_TEXTSIZE(text, font, size, mode) \
        [utils caclulateMultilineTextSize:text withFont:font maxSize:size withMode:mode]
    #define CLMULTILINE_TEXTSIZE_WITH_ATTRIBUTES(text, size, attributes) \
        [utils caclulateMultilineTextSize:text maxSize:size withAttributes:attributes];
#else
    #define CLMULTILINE_TEXTSIZE(text, font, maxSize, mode) [text length] > 0 ? [text \
        sizeWithFont:font constrainedToSize:maxSize lineBreakMode:mode] : CGSizeZero;
#endif

#pragma mark -
#pragma mark - String

#define IS_CHINESE_SYMBOL(chr) ((int)(chr)>127)

